<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>resource-dimensions-config-common</title>
    <%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<script type="text/javascript">
	
	function datagrid(){
		var oTable=	$('#depmtList').dataTable();
		oTable.fnPageChange("first",true);
	}
	 //全选和取消全选
	    function allClick(isSigle)
	    {
	    	if(isSigle!=1) //如果是单选就不支持全选
  	    	{
  	    		var dt_check_all = $('#dt_check_all').attr("checked");
	  	    	var allCheckbox = $("input[name='dt_check']");
	  	    	if(dt_check_all)
	  	    	{
	  	    		
	  	    		allCheckbox.attr("checked",allCheckbox);  //全选
	  	    		$('#depmtList tbody tr').addClass('row_selected');  //背景色全选
	  	    	}else
	  	    	{
	  	    		allCheckbox.attr("checked",false);   //取消全选
	  	    		$('#depmtList tbody tr').removeClass('row_selected');  //背景色取消
	  	    	}
  	    	}
	    }
	$(function(){
		//加载grid
		var oTable=	$('#depmtList').dataTable({
			"bProcessing": true, 
			"bServerSide": true,
			"sServerMethod": 'POST',
			"sAjaxSource":'${pageContext.request.contextPath}/config/resource-dimension-config!list.action',
			"bPaginate": true,
			"bSort": true,
			"bFilter":false,
			"bJQueryUI":false,
			"sPaginationType": "full_numbers",
			//"sScrollX":'100%',
			"sDom":'rt <"bottom"flpi>',
			"aLengthMenu": [[10, 20, 50, 100], [10, 20, 50,100]],
			"aoColumns":[
				{"mDataProp":"checkbox","bSortable": false},
				{"mDataProp":"op","":"center","bSortable": false},
				{"mDataProp":"name","bSortable": false},
				{"mDataProp":"order"},
				{"mDataProp":"firstDimCode","bSortable": false},
				{"mDataProp":"secondDimCode","bSortable": false},
				{"mDataProp":"thirdDimCode","bSortable": false},
				{"mDataProp":"id","bVisible":false}
			], 
			 "oLanguage": { 
			 				"sLengthMenu": "每页 _MENU_ 条",
			 		 		"sZeroRecords": "  ",
							"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
							"sInfoEmpty": "没有找到记录",
							"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
			},
		    "fnServerParams":function(aoData){
		    	var name = $('#name').val();
		    	if(name!='')
		    	{
		    		aoData.push({'name':'name','value':name});
		    	}
		    }
	});
	
	
		$('#depmtList tbody td :checkbox').live('click', function (e) {
			var nTr = $(this).parents('tr')[0]; 
		    	showDetailFlag = true;
			   if ($(nTr).hasClass('row_selected')) {
				  	$(nTr).removeClass('row_selected'); 
			  }else
			  {
			  		$(nTr).addClass('row_selected'); 
			 }
			 if(!$(this).attr("checked")){
			 	$('#allCheck').attr("checked",false);
			 }
		});
		showDetailFlag = false;
	
	});
	function edit(id){
		var url ="iframe:config/resource-dimension-config!input.action?id="+id;
		var opt = { title: "修改资源维度",width:600,height:450,buttons: {}};
		getTopWin(window).openjBox(url,opt,'update-resource-dimension-config',window);
	}
	function preview(id){
		var url ="iframe:config/resource-dimension-config!preview.action?id="+id;
		var opt = { title: "预览资源维度",width:300,height:380,buttons: {}};
		getTopWin(window).openjBox(url,opt,'preview-resource-dimension-config',window);
	}
	function deleteOne(id){
		var submit = function (v, h, f) {
		    if (v == 'ok') {
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/config/resource-dimension-config!delete.action", //请求的action
		    		data : {ids:id}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			window.setTimeout(function () { $.jBox.tip('删除成功。', 'success'); }, 100);
						datagrid();
		    		}
		    	});
		    }
		    else if (v == 'cancel') {
		    }
		    return true; //close
		};
		getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
	}
	function search(){
		var oTable=	$('#depmtList').dataTable();
		oTable.fnPageChange("first",true);
	}
	//得到当前选中的
		function fnGetSelected() {   
			var selections = $('#depmtList tr.row_selected');
		    return selections;
	    } 
		function add() {
			
			var url ="iframe:config/resource-dimension-config!add.action";
			var opt = { title: "新增资源维度",width:600,height:450,buttons: {}};
			
			getTopWin(window).openjBox(url,opt,'add-resource-dimension-config',window);
			
		}
		function deleteAll(){
			var rows = fnGetSelected();
			if(rows.length>0){
				var submit = function (v, h, f) {
				    if (v == 'ok') {
				        $.jBox.tip("正在删除数据...", 'loading');
				        var mydata = {};
						mydata.Ids = new Array(rows.length);
						var oTable =$('#depmtList').dataTable();
						for(var i = 0 ; i<rows.length;i++){
							var aData = oTable.fnGetData(rows[i]);
							mydata.Ids[i] = aData.id;
						}
						$.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/config/resource-dimension-config!delete.action", //请求的action
							data : jQuery.param(mydata,true), //传的参数
							dataType : 'json',
							success : function(data) { //结果
								window.setTimeout(function () { $.jBox.tip('删除成功。', 'success'); }, 100);
								datagrid();
							}
						});
				        
				    }
				    else if (v == 'cancel') {
				       
				    }

				    return true; //close
				};
				getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
			}else{
				top.$.jBox.tip('请选择一条数据','info',{timeout:800});
			}

		}
		function search(){
			var oTable=	$('#depmtList').dataTable();
			oTable.fnPageChange("first",true);
		}
	</script>
  </head>
  
  <body>
    <div class="searchFormStyle">
		<form action="">
			<label>查询名称:</label><input id="name" name="name"> 
			<input type="button" onclick="search();" value="查询" class="searchFormButtonStyle">
		</form>
	</div>
	<h2 class="title-h2"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>资源维度列表</h2>
	<div class="toolbar" id = "toolbar">
	 	<a class="page_add" href="javascript:add();" >新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
 		<a class="page_delete" href="javascript:deleteAll();">批量删除</a>&nbsp;&nbsp;&nbsp;&nbsp;
	</div>
	
	<div>
	<table id="depmtList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
		<thead>
			<tr>
				<th width="1%">&nbsp;&nbsp;<input type='checkbox' name='dt_check_all'
					id="dt_check_all" onclick="allClick()" /></th>
				<th width="5%">操作</th>
				<th width="14%">查询名称</th>
				<th width="6%">显示顺序</th>
				<th width="8%">第一维度</th>
				<th width="8%">第二维度</th>
				<th width="8%">第三维度</th>
			</tr>
		</thead>
	</table>
	</div>
  </body>
</html>
